//
//  WorksPageViewController.swift
//  NDAi
//
//  Created by 丸子 on 2024/8/19.
//

import UIKit
import JXSegmentedView

class WorksPageViewController: BaseViewController {
    lazy var segmentedDataSource:JXSegmentedTitleImageDataSource = {
       let dataSource = JXSegmentedTitleImageDataSource()
        dataSource.isTitleColorGradientEnabled = true
        dataSource.titleImageType = .onlyTitle
        dataSource.titleNormalColor = Theme.color.text_d3
        dataSource.titleSelectedColor = Theme.color.text_d1
        dataSource.titleNormalFont = UIFont.pingFangSCMedium(ofSize: 16)
        dataSource.titleSelectedFont = UIFont.pingFangSCMedium(ofSize: 16)
        dataSource.isItemSpacingAverageEnabled = true
        dataSource.titles = ["绘画", "视频", "音乐"]
        return dataSource
    }()
    
    lazy var segmentedView:JXSegmentedView = {
       let segmentedView = JXSegmentedView()
        segmentedView.defaultSelectedIndex = 0
        segmentedView.backgroundColor = .clear
        segmentedView.listContainer = listContainerView
        segmentedView.dataSource = segmentedDataSource
        let indicator = JXSegmentedIndicatorLineView()
        indicator.indicatorWidth = 30
        indicator.indicatorHeight = 3
        indicator.verticalOffset = 8
        indicator.indicatorColor = UIColor(hexString: "#333333")
        segmentedView.indicators = [indicator]
        return segmentedView
    }()
    
    lazy var listContainerView: JXSegmentedListContainerView! = {
        return JXSegmentedListContainerView(dataSource: self)
    }()
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
//        self.editNav(isCurrent: true)

    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
//        self.editNav(isCurrent: false)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(hexString: "#F3F2F7")
        self.navigationItem.title = "我的作品"
        self.view.addSubview(segmentedView)
        self.view.addSubview(listContainerView)
        
        segmentedView.snp.makeConstraints { make in
            make.top.equalTo(self.safeTop)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(50)
        }
        
        listContainerView.snp.makeConstraints { make in
            make.top.equalTo(segmentedView.snp.bottom).offset(0)
            make.leading.trailing.equalToSuperview()
            make.bottom.equalTo(self.safeBottom)
        }
    }
}
extension WorksPageViewController: JXSegmentedListContainerViewDataSource {
    func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
        if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
            return titleDataSource.dataSource.count
        }
        return 0
    }

    func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
        if index == 0 {
            let vc = PaintingListViewController()
            vc.type = true
            return vc
        }else if index == 1 {
            let vc = VideoWorksViewController()
            return vc
        }else {
            let vc = MusicWorksViewController()
            return vc
        }
    }
}
